<template>
  <div class="competition-grid-container">
    <!-- 页面标题 -->
    <div class="page-header">
      <h1>2025全国大学生创新竞赛</h1>
      <p style="display: inline-block; margin: 10px 0">探索无限可能，激发创新思维</p>
    </div>

    <!-- 宫格布局卡片 -->
    <el-row :gutter="20">
      <el-col :span="6" v-for="(competition, index) in competitions" :key="index">
        <el-card
          class="competition-card"
          :body-style="{ padding: '0px' }"
          @mouseenter="handleMouseEnter(index)"
          @mouseleave="handleMouseLeave(index)"
          :style="{ transform: cardTransforms[index] }"
          @click="handleCardClick(competition)"
        >
          <!-- 卡片图片 -->
          <div class="card-image-container">
            <img :src="competition.imageUrl" alt="竞赛图片" class="card-image" />
            <div class="card-overlay" :style="{ opacity: cardOverlays[index] }"></div>
          </div>

          <!-- 卡片内容 -->
          <div class="card-content">
            <h3 class="competition-title">{{ competition.title }}</h3>
            <p class="competition-desc">{{ competition.description }}</p>
            <div class="competition-meta">
              <span class="meta-item"
                ><i class="el-icon-time"></i> 比赛开始时间：{{ competition.time }}</span
              >
              <span class="meta-item"
                ><i class="el-icon-user"></i>队伍人数：{{ competition.teamSize }}</span
              >
            </div>
            <!-- 是否可以报名 -->
            <div class="enroll-status">
              <button
                class="enroll-btn"
                :class="
                  competition.isEnrollable ? 'enrollable-btn' : 'non-enrollable-btn'
                "
                :disabled="!competition.isEnrollable"
                @click.stop="handleCardClick(competition)"
              >
                <span class="btn-content">
                  <i class="el-icon-edit"></i>
                  <span class="btn-text">{{
                    competition.isEnrollable ? "立即报名" : "暂未开启报名,不可报名"
                  }}</span>
                  <el-icon class="icon-text"><Right /></el-icon>
                </span>
              </button>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <!-- 分页 -->
    <div class="pagination-container">
      <el-pagination
        style="border-radius: 50%"
        v-model:current-page="pagination.currentPage"
        background
        layout="total, prev, pager, next"
        :page-size="pagination.size"
        :pager-count="6"
        :total="pagination.total"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useRouter } from "vue-router";

// 模拟竞赛数据
const competitions = ref([
  {
    id: 1,
    title:
      "人工智能创新应用大赛人工智能创新应用大赛人工智能创新应用大赛人工智能创新应用大赛人工智能创新应用大赛",
    description:
      "探索AI在各领域的创新应用，展现你的技术实力与创意。人工智能创新应用大赛人工智能创新应用大赛人工智人工智能创新应用大赛人工智能创新应用大赛能创新应用大赛",
    time: "2025-06-15",
    teamSize: "5人",
    imageUrl: "https://picsum.photos/400/200?random=1",
    isEnrollable: true, // 可报名状态
  },
  {
    id: 2,
    title: "智慧城市创意设计大赛",
    description: "聚焦城市发展痛点，提供创新性解决方案，共建美好城市。",
    time: "2025-07-20 08:00:00",
    teamSize: "6人",
    imageUrl: "https://picsum.photos/400/200?random=2",
    isEnrollable: false, // 可报名状态
  },
  {
    id: 3,
    title: "绿色能源科技创新赛",
    description: "致力于开发可再生能源技术，推动能源行业的可持续发展。",
    time: "2025-08-10",
    teamSize: "4人",
    imageUrl: "https://picsum.photos/400/200?random=3",
    isEnrollable: true, // 可报名状态
  },
  {
    id: 4,
    title: "虚拟现实交互设计大赛",
    description: "创造沉浸式VR体验，革新人们与数字世界的互动方式。",
    time: "2025-09-05",
    teamSize: "4人",
    imageUrl: "https://picsum.photos/400/200?random=4",
    isEnrollable: false, // 可报名状态
  },
  {
    id: 5,
    title: "大数据分析与应用竞赛",
    description: "从海量数据中挖掘价值，解决实际问题，展现数据驱动决策能力。",
    time: "2025-10-12",
    teamSize: "4人",
    imageUrl: "https://picsum.photos/400/200?random=5",
    isEnrollable: false, // 可报名状态
  },
  {
    id: 6,
    title: "智能硬件开发挑战赛",
    description: "设计并开发创新性硬件产品，结合软件算法实现智能功能。",
    time: "2025-11-18",
    teamSize: "4人",
    imageUrl: "https://picsum.photos/400/200?random=6",
    isEnrollable: true, // 可报名状态
  },
  {
    id: 7,
    title: "移动应用开发大赛",
    description: "开发具有创新性和实用性的移动应用，满足用户需求。",
    time: "2025-12-05",
    teamSize: "2人",
    imageUrl: "https://picsum.photos/400/200?random=7",
    isEnrollable: false, // 可报名状态
  },
  {
    id: 8,
    title: "区块链应用创新大赛",
    description: "探索区块链技术在不同领域的创新应用，解决信任与效率问题。",
    time: "2026-01-20",
    teamSize: "4人",
    imageUrl: "https://picsum.photos/400/200?random=8",
    isEnrollable: true, // 可报名状态
  },
]);

// 卡片动画状态
const cardTransforms = ref(competitions.value.map(() => "scale(1)"));
const cardOverlays = ref(competitions.value.map(() => "0"));

// 路由
const router = useRouter();

// 鼠标悬停事件处理
const handleMouseEnter = (index) => {
  cardTransforms.value[index] = "scale(1.05)";
  cardOverlays.value[index] = "0.1";
};

const handleMouseLeave = (index) => {
  cardTransforms.value[index] = "scale(1)";
  cardOverlays.value[index] = "0";
};

// 卡片点击处理
const handleCardClick = (competition) => {
  if (competition.isEnrollable) {
    // 跳转到报名页面（示例路径）
    router.push({
      name: "competitionDetail",
      query: { id: competition.id },
    });
  } else {
    // 显示不可报名提示
    ElMessage({
      message: "当前比赛暂不可报名，请关注后续开放时间！",
      type: "warning",
    });
  }
};

const pagination = ref({
  currentPage: 1,
  size: 5,
  total: competitions.value.length,
});

//分页
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`);
};
</script>

<style scoped lang="scss">
:deep(.btn-prev) {
  border-radius: 50%;
}
:deep(.btn-next) {
  border-radius: 50%;
}
:deep(.is-active) {
  border-radius: 50%;
}
:deep(.number) {
  border-radius: 50%;
}
.pagination-container {
  display: flex;
  align-items: flex-end;
  margin-top: 20px;
  justify-content: end;
}
.enroll-status {
  display: flex;
  justify-content: flex-end;
  margin-top: 15px;
}

.enroll-btn {
  border: none;
  padding: 8px 15px;
  border-radius: 24px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-content {
  display: flex;
  align-items: center;
}
.icon-text {
  font-size: 14px;
  width: 20px;
}

.enrollable-btn {
  // background: linear-gradient(135deg, #dbe0eb, #f5f6f7);
  background: #9abbfd;
  color: white;
  // box-shadow: 0 4px 12px rgba(64, 158, 255, 0.25);

  &:hover {
    background: linear-gradient(135deg, #3a8ee6, #5cadff);
    box-shadow: 0 6px 16px rgba(64, 158, 255, 0.35);
    transform: translateY(-2px);

    .btn-text {
      animation: shake 0.5s infinite;
    }
  }
}

.non-enrollable-btn {
  background: #909399;
  color: #fff;
  cursor: not-allowed;

  &:hover {
    .btn-text {
      animation: shake-slow 0.5s infinite;
    }
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-2px) rotate(-2deg);
  }
  50% {
    transform: translateX(2px) rotate(1deg);
  }
  75% {
    transform: translateX(-2px) rotate(1deg);
  }
}

@keyframes shake-slow {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-1px) rotate(-0.5deg);
  }
  50% {
    transform: translateX(1px) rotate(0.5deg);
  }
  75% {
    transform: translateX(-0.5px) rotate(0.25deg);
  }
}

:deep(.el-badge__content .el-badge__content--success) {
  width: 80px;
  height: 50px;
}
.competition-grid-container {
  padding: 40px;
  max-width: 1980px;
  margin: 0 auto;
}
/* 新增悬浮状态标签样式 */
.relative {
  position: relative;
}

.absolute {
  position: absolute;
}

.page-header {
  text-align: center;
  margin-bottom: 40px;
}

.page-header h1 {
  font-size: 36px;
  color: #333;
  margin-bottom: 10px;
}

.page-header p {
  font-size: 18px;
  color: #666;
}

.competition-card {
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  cursor: pointer;

  margin-bottom: 25px;
}

.competition-card:hover {
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.card-image-container {
  position: relative;
  height: 180px;
  overflow: hidden;
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.card-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.card-content {
  padding: 20px;
}

.competition-title {
  font-size: 20px;
  font-weight: bold;
  color: #333;
  margin-bottom: 10px;
}

.competition-desc {
  font-size: 14px;
  color: #666;
  margin-bottom: 15px;
  line-height: 1.5;
  height: 42px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.competition-meta {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: #888;
}

.meta-item {
  display: flex;
  align-items: center;
}

.meta-item i {
  margin-right: 5px;
}
// 媒体查询：移动端样式（屏幕宽度 ≤ 768px）
/* 移动端适配（屏幕宽度 ≤ 768px） */
@media (max-width: 768px) {
  .enroll-btn {
    padding: 6px 16px;
    font-size: 13px;
  }
  .enrollable-btn {
    background-color: #165dff;
  }
  .competition-grid-container {
    padding: 12px; /* 减少内边距 */
    height: 100%;
  }
  .page-header {
    text-align: center;
    margin-bottom: 20px;
    margin-top: 30px;
  }
  .page-header h1 {
    font-size: 24px; /* 缩小标题字体 */
  }

  .page-header p {
    font-size: 14px; /* 缩小副标题字体 */
  }

  /* 宫格布局改为单列布局 */
  .el-row {
    --el-row-gutter: 15px; /* 调整栅格间距 */
    flex-direction: column; /* 纵向排列 */
  }

  .el-col {
    flex: 1 0 100%; /* 强制占满宽度 */
    max-width: 100%; /* 取消栅格宽度限制 */
  }

  .competition-card {
    margin-bottom: 15px; /* 调整卡片间距 */
  }

  .card-image-container {
    height: 150px; /* 缩小图片高度 */
  }

  .competition-title {
    font-size: 18px; /* 缩小标题字体 */
  }

  .competition-desc {
    height: auto; /* 取消文本行数限制（可选） */
    -webkit-line-clamp: unset; /* 若需限制行数，可保留并调整数值 */
  }

  .competition-meta {
    flex-direction: column; /* 元数据纵向排列 */
    align-items: flex-start; /* 左对齐 */
    gap: 5px; /* 增加行间距 */
  }
}
</style>
